namespace CloudNinja.Metering.Tests.Support
{
    using System;
    using System.Collections.Generic;
    using System.Threading.Tasks;

    using CloudNinja.Metering.Data;
    using CloudNinja.Metering.Data.Models;

    public class MeteringRepositoryMock : IMeteringRepository
    {
        private readonly IList<MeterData> repository;

        public MeteringRepositoryMock(IList<MeterData> repository)
        {
            this.repository = repository;
        }

        public void Write(string meterTypeId, string tenantId, double value, DateTimeOffset timeStamp, int count)
        {
            this.repository.Add(
                new MeterData
                    {
                        Count = count,
                        MeterTypeId = meterTypeId,
                        TenantId = tenantId,
                        TimePeriod = timeStamp.UtcDateTime,
                        Value = value
                    });
        }

        public void Write(MeterData dataPoint)
        {
            this.Write(new[] { dataPoint });
        }

        public void Write(IEnumerable<MeterData> dataPoints)
        {
            foreach (var meterDataPoint in dataPoints)
            {
                this.repository.Add(meterDataPoint);
            }
        }

        public async Task WriteAsync(MeterData dataPoint)
        {
            throw new NotImplementedException();
        }

        public Task WriteAsync(IEnumerable<MeterData> dataPoint)
        {
            throw new NotImplementedException();
        }

        public bool IfExists(MeterData meterdata)
        {
            throw new NotImplementedException();
        }
    }
}